package com.runmi.webchat.aftersale.web.set.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.runmi.webchat.aftersale.common.result.Result;
import com.runmi.webchat.aftersale.web.base.BaseController;
import com.runmi.webchat.aftersale.web.set.model.UserEdit;
import com.runmi.webchat.aftersale.web.set.model.UserIndex;
import com.runmi.webchat.aftersale.web.set.model.UserSaveMerchant;
import com.runmi.webchat.aftersale.web.set.service.UserService;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;



@Controller
@RequestMapping(value = "/set/user")
public class UserController extends BaseController{

	@Autowired
	private UserService userService;
	

	
	/**
	 * 待作业拣选单查询
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@ApiOperation(value = "用户-用户查询", notes = "用户查询", tags={ "系统设置", })
	@RequestMapping(value = "/index")
	public ModelAndView index(HttpServletRequest request,HttpServletResponse response,UserIndex model){		
		model.setUserId(this.getUserId(request, response));
		model.setPageSize(20);
		ModelAndView mav = new ModelAndView("/set/user/index");		
		userService.index(model);
    	mav.addObject("model", model);
        return mav;
	}
	
	@RequestMapping(value = "/edit")
	public ModelAndView edit(HttpServletRequest request,HttpServletResponse response,UserEdit model){
		//model.setUserId(this.getUserId(request, response));
		ModelAndView mav = new ModelAndView("/set/user/edit");		
		userService.edit(model);
    	mav.addObject("model",model);
        return mav;
		//return "/customer/Customer/seach";
	}
	
	@ApiOperation(value = "用户-根据用户ID查询角色信息", notes = "根据用户ID查询用户信息", tags={ "系统设置", })
	@RequestMapping(value = "/getUserById",produces = { "application/json" },method = RequestMethod.GET)
	public Result getUserById(
			@ApiParam(value = "用户认证信息",required = true)@RequestHeader(value = "tocken", required = true) String tocken,
			@ApiParam(value = "用户ID") @RequestParam(value = "userId",required = true) Integer userId){	
		return userService.getUserById(userId);
    	
	}

	@RequestMapping(value = "/saveUser")
	@ResponseBody
	public Map<String,String> saveUser(HttpServletRequest request,HttpServletResponse response,UserEdit model){
		Map<String,String> result=userService.saveUser(model);
		return result;
	}
	
	
	@RequestMapping(value = "/changeStatus")
	@ResponseBody
	public Map<String,String> changeStatus(HttpServletRequest request,HttpServletResponse response,Integer userId,Byte opType){
	
		Map<String,String> result=userService.changeStatus(this.getUserInfo(request, response),userId,opType);
		return result;
	}
	
	@RequestMapping(value = "/resetPassword")
	@ResponseBody
	public Map<String,String> resetPassword(HttpServletRequest request,HttpServletResponse response,Integer userId){
	
		Map<String,String> result=userService.resetPassword(userId);
		return result;
	}
	
	
	
}